package com.jeesite.modules.front.web;


import com.jeesite.common.entity.Page;
import com.jeesite.modules.HttpRequestDeviceUtils;
import com.jeesite.modules.site.entity.SiteArticle;
import com.jeesite.modules.site.entity.SiteFriendlink;
import com.jeesite.modules.site.service.SiteArticleService;
import com.jeesite.modules.site.service.SiteFriendlinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "${frontPath}/list")
public class ListController {

    @Autowired
    private SiteFriendlinkService siteFriendlinkService;
    @Autowired
    private SiteArticleService siteArticleService;

    @RequestMapping(value = {"show", ""})
    public  String show(String id,Model model, HttpServletRequest request){
        SiteFriendlink siteFriendlink = new SiteFriendlink();
        siteFriendlink.setPos(1);
        Page<SiteFriendlink> page = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("scroll",page.getList());

        SiteArticle siteArticle = new SiteArticle();
        siteArticle.setCategory(Integer.valueOf(id));
        Page<SiteArticle> page2 = siteArticleService.findPage(new Page<SiteArticle>(),siteArticle);
        model.addAttribute("article",page2.getList());
        model.addAttribute("category",id);
        if(HttpRequestDeviceUtils.isMobileDevice(request)){

            return "modules/front/wapcolumn";
        }
        else {
            return "modules/front/column";
        }

    }
}
